//
//  UIButton+ImageLocation.m
//  Logistics
//
//  Created by hy002 on 2018/1/15.
//  Copyright © 2018年 HUYU. All rights reserved.
//

#import "UIButton+ImageLocation.h"

@implementation UIButton (ImageLocation)

- (void)setButtonContentCenter
{
    CGSize imgViewSize,titleSize,btnSize;
    UIEdgeInsets imageViewEdge,titleEdge;
    CGFloat heightSpace = 10.0f;
    
    //设置按钮内边距
    imgViewSize = self.imageView.bounds.size;
    titleSize = self.titleLabel.bounds.size;
    btnSize = self.bounds.size;
    
    imageViewEdge = UIEdgeInsetsMake(heightSpace,0, btnSize.height -imgViewSize.height - heightSpace, - titleSize.width);
    [self setImageEdgeInsets:imageViewEdge];
    titleEdge = UIEdgeInsetsMake(imgViewSize.height +heightSpace, - imgViewSize.width, 0.0, 0.0);
    [self setTitleEdgeInsets:titleEdge];
    
    
}

- (void)setButtonRight
{
    CGSize imgSize = self.currentImage.size;
    CGSize titleSize = [self.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:self.titleLabel.font}];
    UIEdgeInsets  titleEdgeInsets = UIEdgeInsetsMake(0, -imgSize.width-5, 0, imgSize.width+5);
    UIEdgeInsets imgEdgeInsets = UIEdgeInsetsMake(0, 5+titleSize.width, 0, -titleSize.width-5);
    self.titleEdgeInsets = titleEdgeInsets;
    self.imageEdgeInsets = imgEdgeInsets;
    
}

- (CGFloat)getButtonRightWidth
{
    CGSize imgSize = self.currentImage.size;
    CGSize titleSize = [self.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:self.titleLabel.font}];
    UIEdgeInsets  titleEdgeInsets = UIEdgeInsetsMake(0, -imgSize.width-5, 0, imgSize.width+5);
    UIEdgeInsets imgEdgeInsets = UIEdgeInsetsMake(0, 5+titleSize.width, 0, -titleSize.width-5);
    self.titleEdgeInsets = titleEdgeInsets;
    self.imageEdgeInsets = imgEdgeInsets;
    CGFloat cityWidth = imgSize.width+titleSize.width+20*displaywidth;
    return cityWidth;
}


@end
